<?php 
require_once('../Connections/tecno.php'); 
require('scripts/fechaMysqlNormal.php');
session_start();
//$_SESSION['id_cliente'];
$ced = "-1";
if (isset($_REQUEST['buscarC'])) {
  $ced = $_REQUEST['buscarC'];
//$_SESSION['id_cliente']=$ced;   "SELECT * FROM datospersonales, inflaboral WHERE cedula = $ced AND inflaboral.id = datospersonales.id";
}
mysql_select_db($database_tecno, $tecno); //  
$query_buscar = "SELECT * FROM datospersonales WHERE cedula = '$ced'";
$buscar = mysql_query($query_buscar, $tecno) or die(mysql_error());
$row_buscar = mysql_fetch_assoc($buscar);
$totalRows_buscar = mysql_num_rows($buscar);

$idCli = $row_buscar['id'];
$nombre = $row_buscar['nombres'];

mysql_select_db($database_tecno, $tecno);
$query_infLab = "SELECT * FROM inflaboral WHERE inflaboral.id = '$idCli'";
$infLab = mysql_query($query_infLab, $tecno) or die(mysql_error());
$row_lab = mysql_fetch_assoc($infLab);
/* $idC = $row_lab['id'];
$lugar = $row_lab['nombreEmp']; */
$totalRows_lab = mysql_num_rows($infLab); 
/* echo "<script>alert('Este es el id: ".$idC." y el Nombre: ".$lugar."');</script>"; */

mysql_select_db($database_tecno, $tecno);
$query_deuda = "SELECT SUM(monto) as deuda FROM detallescliente WHERE id='$idCli'";
$deuda = mysql_query($query_deuda, $tecno) or die(mysql_error());
$row_deuda = mysql_fetch_assoc($deuda);
$totalRows_deuda = mysql_num_rows($deuda);

mysql_select_db($database_tecno, $tecno);
$query_pagado = "SELECT SUM(cantidad) as pagado FROM pagos WHERE id='$idCli' AND tipo='0'";
$pagado = mysql_query($query_pagado, $tecno) or die(mysql_error());
$row_pagado = mysql_fetch_assoc($pagado);
$totalRows_pagado = mysql_num_rows($pagado);

$deuda = round($row_deuda['deuda'],2);
$pagado = round($row_pagado['pagado'],2);
$debe = ($deuda-$pagado);

?>
<?php if ($totalRows_buscar > 0) {?>
<script language="javascript">

$(document).ready(function(){
	$("#id").val('<?php echo $row_buscar['id']; ?>');	
	$("#cedula").val('<?php echo $row_buscar['cedula']; ?>');	
	$("#nombres").val('<?php echo $row_buscar['nombres']; ?>');	
	$("#apellidos").val('<?php echo $row_buscar['primerApellido']; ?>');	
	$("#direccion").val('<?php echo $row_buscar['direccionHab']; ?>');	
	$("#tlf").val('<?php echo $row_buscar['telefono']; ?>');	
	$("#celular").val('<?php echo $row_buscar['celular']; ?>');	
	$("#tlfOfi").val('<?php echo $row_lab['telefonoEmp']; ?>');
//	$("#dirOfi").val('<?php // echo $row_lab['dirTrabajo']; ?>');
	$("#total").val('<?php echo round($row_deuda['deuda'],2); ?>');
	$("#totalPagado").val('<?php echo round($row_pagado['pagado'],2); ?>');
	$("#totalDebe").val('<?php echo $debe; ?>');
	$("#pago").css("visibility","visible");
	$("#contrato").css("visibility","visible");
	$("#venta").css("visibility","visible");
	$("#prestamo").css("visibility","visible");
	$("#btVarios").css("visibility","visible");	
});
</script>
<?php } else {?>
<?php echo "3"; } ?>
